package tech.tongyu.bct.omssdk.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.tongyu.bct.omssdk.entity.OmsExecutionDTO;
import tech.tongyu.bct.omssdk.entity.OmsExecutionsDTO;
import tech.tongyu.bct.omssdk.entity.OmsVO;
import tech.tongyu.bct.omssdk.entity.Result;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping
public class OmsProxyDemoController {

    @GetMapping("/huarui-service/syncExecutions")
    public Result execution(@RequestBody OmsExecutionsDTO omsExecutionsDTO) {
        System.out.println(omsExecutionsDTO);
        List<OmsExecutionDTO> executions = omsExecutionsDTO.getExecutions();
        System.out.println(executions);
        List<OmsVO> omsVOList = new ArrayList<>();
        for (OmsExecutionDTO execution : executions) {
            Integer res = 1;
            String msg = "成功";
            if (execution.getStrategyId() == null || execution.getTradeSymbol() == null || execution.getSecurityExchange() == null ||
                    execution.getSide() == null || execution.getPositionEffect() == null || execution.getLastQty() == null ||
                    execution.getLastPx() == null || execution.getTradeDate() == null || execution.getExecId() == null ||
                    execution.getOrderId() == null || execution.getFundAccount() == null) {
                res = 0;
                msg = "失败";
            }
            if (execution.getLastQty() < 0 || execution.getOrderId() < 0) {
                res = 0;
                msg = "失败";
            }
            OmsVO omsVO = OmsVO.builder().recordId(execution.getExecId()).result(res).resultMsg(msg).build();
            omsVOList.add(omsVO);
        }
        return Result.success(omsVOList);
    }
    @GetMapping("/huarui-service/syncExecutions/ttest")
    public Result ttest(){
        return Result.success();

    }
}
